export const dicVal = (key)=>{
    let data = [
        {
            code:"MENU",
            value:"菜单"
        },{
            code:"SUBMENU",
            value:"子菜单"
        },{
            code:"GROUP",
            value:"组"
        },{
            code:"BUTTON",
            value:"按钮"
        },{
            code:"SYSTEM",
            value:"系统"
        },{
            code:"CATEGORY",
            value:"平台"
        }       
    ];
    for(let d in data){
        if(data[d].code === key){
            return data[d].value;
        }
    }
    return '';
}

import {queryDics} from '@/api/dic'
export async function queryAllDic(){
    let res = await queryDics(dicType);
    if(res != null && res.code === '200'){
        window.localStorage.setItem("ALL_DIC_ITEM",JSON.stringify(res.data));
    }
}

export function getDicItem(dicType){
    let dic = JSON.parse(window.localStorage.getItem("ALL_DIC_ITEM")).filter(item=>item.code === dicType);
    if(dic != null && dic.length > 0){
        return dic[0].dicList;
    }
    return [];
}

export function getDicValue(dicCode,dicList){
    if(dicList == null || dicList.length === 0){
        return null;
    }
    for(let i in dicList){
        if(dicList[i].code === dicCode){
            return dicList[i].value;
        }
    }
    return null;
}

export const dicType = [
    "DATA_ROLE_TYPE",
    "PROCESS_STATUS",
    "WORKFLOW_STATUS",
    "PROXY_STATUS"
]